package databases

import (
	"github.com/go-xorm/xorm"
	"github.com/kataras/go-errors"
	"gitlab.gaodun.com/golib/gderror"
	"time"
	"permission/config"
	"permission/vigo_loger"
)

type Tpo_Sys_Role_Navigation_Function struct {
	Id           int64     `xorm:"pk autoincr"` // int(11) NOT NULL AUTO_INCREMENT,
	RoleId       int64     //int(11) NOT NULL,
	FunctionId   int64     // int(11) NOT NULL,
	NavigationId int64     //int(11) NOT NULL,
	CreateId     int64     //int(11) NOT NULL,
	CreateTime   time.Time `xorm:"DateTime created"` // datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
}

type RoleNavFuncFactory struct {
	Table        Tpo_Sys_Role_Navigation_Function
	engine       *xorm.Engine
	RowsSlicePtr []Tpo_Sys_Role_Navigation_Function
}

// 返回
func NewRoleNavFuncFactory() *RoleNavFuncFactory {
	funcFac := RoleNavFuncFactory{}
	funcFac.engine, _ = config.InitEng()
	return &funcFac
}

func (rnf *RoleNavFuncFactory) FindByRoleIds(roleIds ...int64) error {
	if len(roleIds) == 0 {
		return errors.New("role id is null")
	}
	err := rnf.engine.In("RoleId", roleIds).Find(&(rnf.RowsSlicePtr))
	if err != nil {
		vigo_loger.AddGrayLog(gderror.New(err.Error()).Error())
	}
	return err
}
